/**
 * Created by FreezeSoul on 2017/8/11.
 */
define([
    "app/core/base",
    "jquery",
    "underscore",
    'JSONParse',
    'loglevel'
], function (Chart, $, _, JSON, log) {

    var demo = Chart.extend({
        constructor: function (layout) {
            this._layout = layout;
            this._element = null;
            this._container = null;
            this._option = {
                Binding: [],
                Events: [],
                Extend: {},
                Option: {}
            };
        },
        init: function (element) {
            try {
                this._container = element;
            } catch (e) {
                log.error(e);
            }
        },
        _render: function () {
            $(this._container).empty();
            var $iframe = $('<iframe src="" width="100%" height="100%" frameborder="0"></iframe>');
            $iframe.attr("src", "app/plugins/demo/bg-starriest/resource/index.html?" + (new Date()).getTime()).attr("scrolling", "no").appendTo(this._container);
            return $iframe;
        },
        example: function () {
            try {
                this._element = this._render();
            } catch (e) {
                log.error(e);
            }
        },
        setData: function (data) {
            try {
                this._element = this._render();
            } catch (e) {
                log.error(e);
            }
        },
        setOption: function (option) {
            try {
                return this._option = $.extend(true, {}, option);
            } catch (e) {
                log.error(e);
            }
        },
        getOption: function () {
            return this._option;
        },
        setTheme: function (theme) {
            try {
            } catch (e) {
                log.error(e);
            }
        },
        resize: function () {
            try {
            } catch (e) {
                log.error(e);
            }
        },
        showLoading: function () {
            try {
                if (this._layout && this._layout.showLoading) {
                    this._layout.showLoading(this);
                }
            } catch (e) {
                log.error(e);
            }
        },
        hideLoading: function () {
            try {
                if (this._layout && this._layout.hideLoading) {
                    this._layout.hideLoading(this);
                }
            } catch (e) {
                log.error(e);
            }
        },
        dispose: function () {
            try {
                $(this._element).remove();
            } catch (e) {
                log.error(e);
            }
        },
        getChart: function () {
            return this._element;
        }
    });

    return demo;
});